package com.zhdl.network.prefirertu.after;

import com.project.command.instruction.strategy.abs.AbsAfterControlCommand;
import com.project.command.instruction.strategy.process.data.AfterStrategyParam;
import com.zhdl.common.eventbus.center.EventBusCenter;
import com.zhdl.common.eventbus.event.PreFireEvent;
import com.zhdl.network.prefirertu.dto.UpsFrameDto;
import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service(UpsAfterService.UPS_AFTER_SERVICE)
public class UpsAfterService extends AbsAfterControlCommand<UpsFrameDto, ByteBuf> {
    public static final String UPS_AFTER_SERVICE = "preFireUpsAfterService";

    /**
     * 后置处理结果判断
     *
     * @param resp
     * @return
     */
    @Override
    public boolean afterResultJudge(AfterStrategyParam resp) {
        List<UpsFrameDto> list = resp.getNewData();
        //此处接收串口或网口客户端回应代码,并处理
        UpsFrameDto upsFrameDto = list.get(0);
        log.info("===> 收到客户端信息 {}", upsFrameDto);
        PreFireEvent preFireEvent = new PreFireEvent();
        preFireEvent.setType("com");
        preFireEvent.setPort(resp.getPortKey());
        preFireEvent.setEvent(resp);
        EventBusCenter.getEventBus().post(preFireEvent);
        return true;
    }
}
